package com.google.android.play.core.assetpacks;

import java.io.FilterInputStream;
import java.io.InputStream;
import java.util.Arrays;

final class m0 extends FilterInputStream {

    /* renamed from: b  reason: collision with root package name */
    private byte[] f2568b = new byte[4096];

    /* renamed from: c  reason: collision with root package name */
    private long f2569c;

    /* renamed from: d  reason: collision with root package name */
    private boolean f2570d = false;
    private boolean e = false;

    m0(InputStream inputStream) {
        super(inputStream);
    }

    private final int a(byte[] bArr, int i, int i2) {
        return Math.max(0, super.read(bArr, i, i2));
    }

    private final q2 c(int i, String str, long j, int i2, boolean z) {
        return q2.a(str, j, i2, z, Arrays.copyOf(this.f2568b, i));
    }

    private final void d(long j) {
        int length = this.f2568b.length;
        if (j > ((long) length)) {
            do {
                length += length;
            } while (((long) length) < j);
            this.f2568b = Arrays.copyOf(this.f2568b, length);
        }
    }

    private final boolean e(int i, int i2) {
        return a(this.f2568b, i, i2) == i2;
    }

    /* access modifiers changed from: package-private */
    public final q2 b() {
        byte[] bArr;
        if (this.f2569c > 0) {
            do {
                bArr = this.f2568b;
            } while (read(bArr, 0, bArr.length) != -1);
        }
        if (this.f2570d || this.e) {
            return q2.a((String) null, -1, -1, false, (byte[]) null);
        }
        int a2 = a(this.f2568b, 0, 30);
        if (a2 != 30 && !e(a2, 30 - a2)) {
            this.f2570d = true;
            return c(a2, (String) null, -1, -1, true);
        } else if (w1.e(this.f2568b, 0) != 67324752) {
            this.e = true;
            return c(a2, (String) null, -1, -1, false);
        } else {
            long e2 = w1.e(this.f2568b, 18);
            if (e2 != 4294967295L) {
                int g = w1.g(this.f2568b, 8);
                int g2 = w1.g(this.f2568b, 26);
                int i = g2 + 30;
                d((long) i);
                int a3 = a(this.f2568b, 30, g2);
                int i2 = a3 + 30;
                if (a3 == g2 || e(i2, g2 - a3)) {
                    String str = new String(this.f2568b, 30, g2);
                    int g3 = w1.g(this.f2568b, 28);
                    int i3 = i + g3;
                    d((long) i3);
                    int a4 = a(this.f2568b, i, g3);
                    int i4 = i + a4;
                    if (a4 == g3 || e(i4, g3 - a4)) {
                        this.f2569c = w1.e(this.f2568b, 18);
                        return c(i3, str, e2, g, false);
                    }
                    this.f2570d = true;
                    return c(i4, str, e2, g, true);
                }
                this.f2570d = true;
                return c(i2, (String) null, e2, g, true);
            }
            throw new v0("Files bigger than 4GiB are not supported.");
        }
    }

    /* access modifiers changed from: package-private */
    public final boolean f() {
        return this.f2570d;
    }

    /* access modifiers changed from: package-private */
    public final boolean g() {
        return this.e;
    }

    /* access modifiers changed from: package-private */
    public final long h() {
        return this.f2569c;
    }

    public final int read(byte[] bArr) {
        return read(bArr, 0, bArr.length);
    }

    public final int read(byte[] bArr, int i, int i2) {
        long j = this.f2569c;
        if (j <= 0 || this.f2570d) {
            return -1;
        }
        int a2 = a(bArr, i, (int) Math.min(j, (long) i2));
        this.f2569c -= (long) a2;
        if (a2 != 0) {
            return a2;
        }
        this.f2570d = true;
        return 0;
    }
}
